package com.example.mavendemo.controller;


import ch.qos.logback.core.util.StringUtil;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    private List<MessageInfo> messages = new LinkedList<>();

    @RequestMapping("/publish")
    public boolean publish(MessageInfo messageInfo) {
        if(!StringUtils.hasLength(messageInfo.getFrom())
                || !StringUtils.hasLength(messageInfo.getTo())
                || !StringUtils.hasLength(messageInfo.getMessage())) {
            return false;
        }
        messages.add(messageInfo);
        return true;
    }



    @RequestMapping("/getMessage")
    public List<MessageInfo> getMessage() {
        return messages;
    }
}
